#include "IFCS.h"

hgeSprite* Ammo::spr = 0;

IFCS::IFCS(): count(0)
{
	head = new Ammo();
	tail = new Ammo();
	head->next = tail;
	tail->prev = head;
}

IFCS::~IFCS()
{
	Ammo *p = head, *q = p->next;
	for (; q; p = q, q = q->next) {
		delete p;
	}
	delete p;
}

void IFCS::addAmmo(Ammo* amm)
{
	amm->prev = tail->prev;
	amm->next = tail;
	tail->prev->next = amm;
	tail->prev = amm;
	amm->ifcs = this;
	++count;
}

Ammo* IFCS::removeAmmo(Ammo* amm)
{
	Ammo* t = amm->next;
	amm->prev->next = amm->next;
	amm->next->prev = amm->prev;
	delete amm;
	--count;
	return  t;
}

void IFCS::Update(float dt) {
	for (Ammo* p = head->next; p != tail; p = p->next)
		if (p->update(dt))
			p = removeAmmo(p)->prev;
}

void IFCS::Render()
{
	for (Ammo* p = head->next; p != tail; p = p->next) p->render();
}
